package com.ruoyi.project.poem.topictemplate.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.poem.topictemplate.domain.TopicTemplate;
import com.ruoyi.project.poem.topictemplate.service.ITopicTemplateService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 诗集模版Controller
 * 
 * @author shixiangwen
 * @date 2022-06-29
 */
@Controller
@RequestMapping("/poem/topictemplate")
public class TopicTemplateController extends BaseController
{
    private String prefix = "poem/topictemplate";

    @Autowired
    private ITopicTemplateService topicTemplateService;

    @RequiresPermissions("poem:topictemplate:view")
    @GetMapping()
    public String topictemplate()
    {
        return prefix + "/topictemplate";
    }

    /**
     * 查询诗集模版列表
     */
    @RequiresPermissions("poem:topictemplate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TopicTemplate topicTemplate)
    {
        startPage();
        List<TopicTemplate> list = topicTemplateService.selectTopicTemplateList(topicTemplate);
        return getDataTable(list);
    }

    /**
     * 导出诗集模版列表
     */
    @RequiresPermissions("poem:topictemplate:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TopicTemplate topicTemplate)
    {
        List<TopicTemplate> list = topicTemplateService.selectTopicTemplateList(topicTemplate);
        ExcelUtil<TopicTemplate> util = new ExcelUtil<TopicTemplate>(TopicTemplate.class);
        return util.exportExcel(list, "topictemplate");
    }

    /**
     * 新增诗集模版
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存诗集模版
     */
    @RequiresPermissions("poem:topictemplate:add")
    @Log(title = "诗集模版", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TopicTemplate topicTemplate)
    {
        return toAjax(topicTemplateService.insertTopicTemplate(topicTemplate));
    }

    /**
     * 修改诗集模版
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TopicTemplate topicTemplate = topicTemplateService.selectTopicTemplateById(id);
        mmap.put("topicTemplate", topicTemplate);
        return prefix + "/edit";
    }

    /**
     * 修改保存诗集模版
     */
    @RequiresPermissions("poem:topictemplate:edit")
    @Log(title = "诗集模版", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TopicTemplate topicTemplate)
    {
        return toAjax(topicTemplateService.updateTopicTemplate(topicTemplate));
    }

    /**
     * 删除诗集模版
     */
    @RequiresPermissions("poem:topictemplate:remove")
    @Log(title = "诗集模版", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(topicTemplateService.deleteTopicTemplateByIds(ids));
    }
}
